import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() => runApp(const PopupMenuButtonWidget());

class PopupMenuButtonWidget extends StatelessWidget {
  const PopupMenuButtonWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      theme: ThemeData(
        primaryColor: Colors.blue,
      ),
      home: Scaffold(
          appBar: AppBar(title: const Text("Flutter UI基础Widget -- 按钮")),
          body: PopupMenuButton<MenuItem>(
            child: const Text('更多'),
            onSelected: (MenuItem result) {
              if (kDebugMode) {
                print('click ' + result.toString());
              }
            },
            itemBuilder: (BuildContext context) => <PopupMenuEntry<MenuItem>>[
              const PopupMenuItem<MenuItem>(
                value: MenuItem.menuA,
                child: Text('menu A'),
              ),
              const PopupMenuItem<MenuItem>(
                value: MenuItem.menuB,
                child: Text('menu B'),
              ),
              const PopupMenuItem<MenuItem>(
                value: MenuItem.menuC,
                child: Text('menu C'),
              ),
              const PopupMenuItem<MenuItem>(
                value: MenuItem.menuD,
                child: Text('menu D'),
              ),
            ],
          )),
    );
  }
}

enum MenuItem { menuA, menuB, menuC, menuD }
